package com.wanxi.test;

import java.util.Random;
import java.util.Scanner;

public class ArrayFor {
    //    private static Random random = new Random();
    {
        System.out.println(11);
    }

    public static void main(String[] args) {
        ArrayFor arrayFor = new ArrayFor();

        /**
         * 1.创建数组
         * 2.遍历打印
         */
//        int[] arr={1,2,4,5,56};
//        1.数组的长度，2.数组的内容
        int length = getNum("请输入数组的长度");
        int[] arr = getArr(length);
        myFor(arr);
    }

    private static void myFor(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i] + "]");
            } else {
                System.out.print(arr[i] + ", ");
            }
        }
    }

    private static int[] getArr(int length) {
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i] = getRandom(10);
        }
        return arr;
    }

    /**
     * 数组内容随机数：定义内容大小
     *
     * @param i
     * @return
     */
    private static int getRandom(int i) {
        Random random = new Random();
        return random.nextInt(10);
    }

    private static int getNum(String tips) {
        Scanner scanner = new Scanner(System.in);
        System.out.println(tips);
        int num = scanner.nextInt();
        return num;
    }
}
